﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MpeCore;
using MpeCore.Classes;
using Path = System.IO.Path;

namespace NewMpeInstaller
{

    /// <summary>
    /// Interaction logic for ExtensionBlock.xaml
    /// </summary>
    public partial class ExtensionBlock : UserControl
    {
        public PackageClass Package;
        public string Description;

        public static event ExtensionSelectedHandler ExtensionSelected;
        public ExtensionBlock(PackageClass pack, bool installed, bool haveupdate)
        {
            
            InitializeComponent();
            this.Package = pack;
            this.ExtensionTitle.Text = this.Package.GeneralInfo.Name;
            this.ExtensionInstalled.Visibility = (installed ? Visibility.Visible : Visibility.Hidden);
            this.ExtensionHaveupdate.Visibility = (haveupdate ? Visibility.Visible : Visibility.Hidden);
            this.ExtensionVersion.Text = this.Package.GeneralInfo.Version.ToString();
            if (File.Exists(this.Package.LocationFolder + "icon.png"))
            {
                try
                {
                    this.ExtensionIcon.Source = new BitmapImage(new Uri(this.Package.LocationFolder + "icon.png"));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("here"); 
                }

            }


        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Grid selected = sender as Grid;

            PackageClass pack = this.Package;
            Description = Package.GeneralInfo.ExtensionDescription;
            ExtensionSelected(this, new ExtensionSelectedArgs());

        }
    }
    public delegate void ExtensionSelectedHandler(object sender, ExtensionSelectedArgs e);
    public class ExtensionSelectedArgs : System.EventArgs
    {

    }
}
